import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs' //国际化
import { createPinia } from 'pinia'
import persistedState from 'pinia-persistedstate'
import mitt from 'mitt'

import VTable from '@/components/v-table/index.vue'

const app = createApp(App)

//全局注册图标组件
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

const store = createPinia()
// pinia本地持久化，将menu模块的数据存储到localStorage
store.use(
  persistedState({
    key: 'erabbit-shop',
    paths: ['menu'],
  })
)

// 兄弟组件数据的传递
const Mit = mitt()
declare module 'vue' {
  export interface ComponentCustomProperties {
    $Bus: typeof Mit
  }
}
app.config.globalProperties.$Bus = Mit // 全局兄弟组件传递数据
app
  .component('VTable', VTable)
  .use(ElementPlus, { locale: zhCn })
  .use(router)
  .use(store)
  .mount('#app')
